home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
Dev
/
Oberon
/
source
/
Library
/
MathL.mod
< prev
next >
Wrap
Text File
|
1995-06-29
|
4KB
|
171 lines
(*************************************************************************
$RCSfile: MathL.mod $
Description: Basic functions for LONGREALs.
Created by: fjc (Frank Copeland)
$Revision: 1.4 $
$Author: fjc $
$Date: 1995/06/04 23:22:41 $
Copyright © 1994-1995, Frank Copeland.
This file is part of the Oberon-A Library.
See Oberon-A.doc for conditions of use and distribution.
Thanks to Mike Griebling and Rene Hogendoorn for their assistance.
*************************************************************************)
MODULE MathL;
(*
This module will not be implemented until the following two modules are
implemented.
IMPORT m1 := MathIeeeDoubBas, m2 := MathIeeeDoubTrans;
CONST
pi *= 3.14159265358979323846;
e *= 2.71828182845904523536;
PROCEDURE sqrt * ( x : LONGREAL ) : LONGREAL;
BEGIN (* sqrt *)
RETURN m2.Sqrt (x)
END sqrt;
PROCEDURE power * ( x, base : LONGREAL ) : LONGREAL;
BEGIN (* power *)
RETURN m2.Pow (base, x)
END power;
PROCEDURE exp * ( x : LONGREAL ) : LONGREAL;
BEGIN (* exp *)
RETURN m2.Exp (x)
END exp;
PROCEDURE ln * ( x : LONGREAL ) : LONGREAL;
BEGIN (* ln *)
RETURN m2.Log (x)
END ln;
PROCEDURE log * ( x, base : LONGREAL ) : LONGREAL;
BEGIN (* log *)
RETURN m2.Log (x) / m2.Log (base)
END log;
PROCEDURE round * ( x : LONGREAL ) : LONGREAL;
BEGIN (* round *)
IF x < 0.0 THEN RETURN m1.Ceil (x - 0.5)
ELSE RETURN m1.Floor (x + 0.5)
END
END round;
PROCEDURE sin * ( x : LONGREAL ) : LONGREAL;
BEGIN (* sin *)
RETURN m2.Sin (x)
END sin;
PROCEDURE cos * ( x : LONGREAL ) : LONGREAL;
BEGIN (* cos *)
RETURN m2.Cos (x)
END cos;
PROCEDURE tan * ( x : LONGREAL ) : LONGREAL;
BEGIN (* tan *)
RETURN m2.Tan (x)
END tan;
PROCEDURE arcsin * ( x : LONGREAL ) : LONGREAL;
BEGIN (* arcsin *)
RETURN m2.Asin (x)
END arcsin;
PROCEDURE arccos * ( x : LONGREAL ) : LONGREAL;
BEGIN (* arccos *)
RETURN m2.Acos (x)
END arccos;
PROCEDURE arctan * ( x : LONGREAL ) : LONGREAL;
BEGIN (* arctan *)
RETURN m2.Atan (x)
END arctan;
PROCEDURE arctan2 * ( xn, xd : LONGREAL ) : LONGREAL;
CONST piBy2 = 1.57079632679489161923;
VAR res : LONGREAL;
BEGIN
IF xd = 0.0 THEN
IF xn = 0.0 THEN RETURN 0.0
ELSE IF xn < 0.0 THEN RETURN -piBy2 ELSE RETURN piBy2 END
END
(* Checking for Overflow/Underflow at this point appears unnecessary,
as testing without the checks seems to produce the correct results.
[Possibly 'famous last words' by fjc :-)]
ELSIF Overflow(xn/xd) THEN
IF xn < 0.0 THEN RETURN -piBy2 ELSE RETURN piBy2 END
ELSIF Underflow(xn/xd) THEN res := 0.0
*)
ELSE res := arctan(ABS(xn/xd))
END;
IF xd < 0.0 THEN res := pi - res END;
IF xn < 0.0 THEN RETURN -res ELSE RETURN res END
END arctan2;
PROCEDURE sinh * ( x : LONGREAL ) : LONGREAL;
BEGIN (* sinh *)
RETURN m2.Sinh (x)
END sinh;
PROCEDURE cosh * ( x : LONGREAL ) : LONGREAL;
BEGIN (* cosh *)
RETURN m2.Cosh (x)
END cosh;
PROCEDURE tanh * ( x : LONGREAL ) : LONGREAL;
BEGIN (* tanh *)
RETURN m2.Tanh (x)
END tanh;
PROCEDURE arcsinh * ( x : LONGREAL ) : LONGREAL;
BEGIN (* arcsinh *)
RETURN m2.Log (x + m2.Sqrt (x * x + 1.0))
END arcsinh;
PROCEDURE arccosh * ( x : LONGREAL ) : LONGREAL;
BEGIN (* arccosh: x >= 1.0 *)
RETURN m2.Log (x + m2.Sqrt (x * x - 1.0))
END arccosh;
PROCEDURE arctanh * ( x : LONGREAL ) : LONGREAL;
BEGIN (* arctanh: 0 <= x*x <= 1 *)
RETURN 0.5 * m2.Log ((1.0 + x) / (1.0 - x))
END arctanh;
BEGIN
ASSERT (m1.base # NIL, 100); ASSERT (m2.base # NIL, 100)
*)
END MathL.